package com.wans.guli.order.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class OrderExecutorConfig {

    @Autowired
    private OrderFieldConfig orderFieldConfig;

    // Product 一个线程池
    @Bean("cartExecutor")
    public Executor executor() {
        return new ThreadPoolExecutor(
                orderFieldConfig.getCorePoolSize(),
                orderFieldConfig.getMaxPoolSize(),
                orderFieldConfig.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(orderFieldConfig.getQueueSize()),
                new ThreadPoolExecutor.DiscardPolicy()
        );
    }

}
